﻿#region COPYRIGHT© 2009-2012 Phillip Clark. All rights reserved.

// For licensing information see License.txt (MIT style licensing).

#endregion

using System;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using FlitBit.Cache.CodeContracts;
using FlitBit.Core.Parallel;

namespace FlitBit.Cache
{
	/// <summary>
	///   Interface for objects that resolve items that are missing from the cache.
	/// </summary>
	/// <typeparam name="TKey">key type K</typeparam>
	/// <typeparam name="TValue">item type R</typeparam>
	[ContractClass(typeof(ContractForICacheItemResolver<,>))]
	public interface ICacheItemResolver<TKey, TValue>
	{
		/// <summary>
		///   Gets the number of items attempted.
		/// </summary>
		int AttemptCount { get; }

		/// <summary>
		///   Gets the number of items resolved.
		/// </summary>
		int ResolveCount { get; }

		/// <summary>
		///   Tries to resolve an item missing from the cache.
		/// </summary>
		/// <param name="key">the item's key</param>
		/// <param name="continuation">A continuation where the result is returned upon completion.</param>
		void TryResolve(TKey key, Continuation<Tuple<ResolutionKinds, TKey, TValue>> continuation);

		/// <summary>
		///   Tries to resolve many items missing from the cache.
		/// </summary>
		/// <param name="keys">the item's key</param>
		/// <param name="continuation">A continuation where the results are returned upon completion.</param>
		void TryResolveMany(IEnumerable<TKey> keys, Continuation<IEnumerable<Tuple<ResolutionKinds, TKey, TValue>>> continuation);
	}

	namespace CodeContracts
	{
		/// <summary>
		///   CodeContracts Class for ICacheItemResolver&lt;,>
		/// </summary>
		[ContractClassFor(typeof(ICacheItemResolver<,>))]
		internal abstract class ContractForICacheItemResolver<TKey, TValue> : ICacheItemResolver<TKey, TValue>
		{
			#region ICacheItemResolver<K,V> Members

			public int AttemptCount { get { throw new NotImplementedException(); } }

			public int ResolveCount { get { throw new NotImplementedException(); } }

			public void TryResolve(TKey key, Continuation<Tuple<ResolutionKinds, TKey, TValue>> continuation)
			{
				Contract.Requires<ArgumentNullException>(continuation != null);
				throw new NotImplementedException();
			}

			public void TryResolveMany(IEnumerable<TKey> keys, Continuation<IEnumerable<Tuple<ResolutionKinds, TKey, TValue>>> continuation)
			{
				Contract.Requires<ArgumentNullException>(keys != null);
				Contract.Requires<ArgumentNullException>(continuation != null);

				throw new NotImplementedException();
			}

			#endregion
		}
	}
}